package com.dunshan.member.controller;

import brave.baggage.BaggageField;
import com.dunshan.member.feign.CartServiceFeignClient;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * @author dunshan
 * @program: dunshan-pef
 * @description: 会员服务index
 * @date 2021-10-02 14:47:29
 */
@Log4j2
@RestController
public class MemeberController {

    @Resource
    CartServiceFeignClient cartFeignClient;

    @Autowired
    HttpServletRequest request;

    @GetMapping("/member/user/{id}")
    public Object memberUser(@PathVariable(value = "id") Integer id) {
        String dunshan = request.getHeader("dunshan");
        String result = cartFeignClient.openCartInfo(id);
        log.info("/member/user/" + dunshan);

//        BaggageField dunsha = BaggageField.getByName("dunshan");
//        String value = dunsha.getValue();
//        System.out.println(value);

        result = "-> dunshan-member" + result;
        HashMap<String, Object> map = new HashMap<>();
        map.put("data", result);
        map.put("dunshan", dunshan);
        return map;
    }


    @GetMapping("/tag")
    public Object tagMdcInfo() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("data", "调试！");
        return map;
    }


    /**
     * 查询用户信息
     *
     * @return
     */
    @GetMapping("/admin/info")
    public Object selectAdmin() {
        return cartFeignClient.selectInfo();
    }
}
